/*判断是闰年还是平年*/
function runNian(y){
    if(y % 400 ===0 ||(y % 4 ===0 && y % 100 !==0)){
        return true;
    }else {
        return false;
    }
}

/*算出1980年到2018年的总天数*/
//今年年份
var years =2019;

//今年的月份
var sounth = 5;

document.querySelector("#danian").innerHTML = years;
document.querySelector("#xiaoyue").innerHTML = sounth;

//总天数
var days = 0;

//从1980年到2019年如果是闰年总天数
for(i=1980; i<years; i++){
    if(runNian(i)){
        days += 366;
    }else {
        days += 365;
    }
}


/*算出2019年一到四月的天数*/
for(k=1; k<sounth; k++){
    switch (k){
        case 1:
            days +=31;
            break;
        case 2:
            if(runNian(years)){
                days +=29;
            }else {
                days +=28;
            }
            break;
        case 3:
            days +=31;
            break;
        case 4:
            days +=30;
            break;
        case 5:
            days +=31;
            break;
        case 6:
            days +=30;
            break;
        case 7:
            days +=31;
            break;
        case 8:
            days +=31;
            break;
        case 9:
            days +=30;
            break;
        case 10:
            days +=31;
            break;
        case 11:
            days +=30;
            break;
        case 12:
            days +=31;
            break;
    }
}
console.log(days);



/*算出本月的天数*/
var day = 0;
switch (sounth){
    case 1:
        day +=31;
        break;
    case 2:
        if(runNian(years)){
            day +=29;
        }else {
            day +=28;
        }
        break;
    case 3:
        day +=31;
        break;
    case 4:
        day +=30;
        break;
    case 5:
        day +=31;
        break;
    case 6:
        day +=30;
        break;
    case 7:
        day +=31;
        break;
    case 8:
        day +=31;
        break;
    case 9:
        day +=30;
        break;
    case 10:
        day +=31;
        break;
    case 11:
        day +=30;
        break;
    case 12:
        day +=31;
        break;
}
console.log(day);



/*算出上月的天数*/
var prevday = 0;
if(sounth ==1){
    prevday = 31;
}else {
    switch (sounth-1){
        case 1:
            prevday +=31;
            break;
        case 2:
            if(runNian(years)){
                prevday +=29;
            }else {
                prevday +=28;
            }
            break;
        case 3:
            prevday +=31;
            break;
        case 4:
            prevday +=30;
            break;
        case 5:
            prevday +=31;
            break;
        case 6:
            prevday +=30;
            break;
        case 7:
            prevday +=31;
            break;
        case 8:
            prevday +=31;
            break;
        case 9:
            prevday +=30;
            break;
        case 10:
            prevday +=31;
            break;
        case 11:
            prevday +=30;
            break;
        case 12:
            prevday +=31;
            break;
    }
}

console.log(prevday);

//因为1980年一月是星期二，我想让他从星期日开始算，所有总天数加二
days += 2;
console.log(days);


//算出本月1号是星期几
var yueChu = days % 7;
console.log(yueChu);



//当前页面一共可以放42天
var num = 42;


//求出本页下个月多少天
var nextDays = num - day - yueChu;


//提取今天的日期
var thisdate = new Date().getDate();

//获取填入date1标签，以便于填入标签中的内容
var date1 = document.querySelector("#date1");

//算出本页上个月的的余数从从几开始
//因为上个月的余数为3、并且上个月的数为30天，30-3得27，因为只有三个空位，所以在加一
for(var j = prevday - yueChu + 1; j<=prevday; j++){
    date1.innerHTML +="<span class='h'>"+ j +"</span>"
}

//算出本月的日期
for(var a=1; a<=day; a++){
    if(a == thisdate){
        date1.innerHTML +="<span class='today'>"+ a +"</span>"
    }else {
        date1.innerHTML +="<span>"+ a +"</span>"
    }
}

//算出下个月的日期
for(var jk =1; jk<=nextDays; jk++){
    date1.innerHTML +="<span>" + jk + "</span>"
}

